package com.linyu.linpicturebackend.common.utils;

import com.linyu.linpicturebackend.common.exception.BusinessException;
import com.linyu.linpicturebackend.common.exception.ErrorCode;

/**
 * ThrowUtils 异常处理工具类
 *
 * @author liyang
 * @since 2024/12/15 22:36
 */
public class ThrowUtils {

    /**
     * 条件成立则抛出异常
     * @param condition 条件
     * @param runtimeException 异常
     */
    public static void throwIf(boolean condition, RuntimeException runtimeException){
        if (condition){
            throw runtimeException;
        }
    }

    /**
     * 条件成立则抛出异常
     * @param condition 条件
     * @param errorCode 错误码
     */
    public static void throwIf(boolean condition, ErrorCode errorCode){
        if (condition){
            throw new BusinessException(errorCode);
        }
    }

    /**
     * 条件成立则抛出异常
     * @param condition 条件
     * @param errorCode 错误码
     * @param message 自定义错误信息
     */
    public static void throwIf(boolean condition, ErrorCode errorCode, String message){
        if (condition){
            throw new BusinessException(errorCode, message);
        }
    }

}